<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('财务收支记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>财务记录类型：</label>
                                <div class="col-sm-8">
                                    <select name="dictCode" class="form-control m-b" th:with="type=${@dict.getType('sys_financial_record')}" required>
                                        <option value="">-- 请选择 --</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>金额：</label>
                                <input type="text" name="amount" placeholder="请输入金额"/>
                            </li>
                            <li>
                                <label>记录日期：</label>
                                <input type="text" class="time-input" placeholder="请选择记录日期" name="recordDate"/>
                            </li>
<!--                            <li>-->
<!--                                <label>关联数据：</label>-->
<!--                                <input type="text" name="relatedId"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:financial:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:financial:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:financial:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:financial:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:financial:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:financial:remove')}]];
        var prefix = ctx + "system/financial";
        // 存储财务记录类型字典数据的变量
        var financialRecordTypeDict = /*[[${@dict.getType('sys_financial_record')}]]*/ [];
        // 将字典数据转换为键值对形式，方便查找
        var financialRecordTypeMap = {};
        financialRecordTypeDict.forEach(function(item) {
            financialRecordTypeMap[item.dictValue] = item.dictLabel;
        });

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "财务收支记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'recordId',
                    title: '记录ID',
                    visible: false
                },
                {
                    field: 'dictCode',
                    title: '财务记录类型',
                    formatter: function(value) {
                        if (typeof value === 'object') {
                            console.error('dictCode 字段的值是一个对象:', value);
                            return '未知';
                        }
                        const label = financialRecordTypeMap[value];
                        if (label) {
                            return label;
                        } else {
                            console.error('未找到对应的财务记录类型标签，value:', value);
                            return '未知类型';
                        }
                    }
                },
                {
                    field: 'relateName',
                    title: '关联信息'
                },
                {
                    field: 'amount',
                    title: '金额'
                },
                {
                    field: 'recordDate',
                    title: '记录日期'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        console.log(row)
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.recordId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.recordId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>